<%- include header %>
<!-- 主题内容start -->
<table class="table table-bordered table-striped table-condensed table-hover">
    <tr>
        <th class="span3" colspan="5"><h4 style="text-align: center">咖啡厅(咖啡厅总数：<%- count %>个|当前页：<%- page.num %>/<%- page.pageCount %>页)</h4></th>
    </tr>
    <tr>
        <th class="span3">名称</th>
        <th class="span3">地址</th>
        <th class="span2">简介/编辑</th>
        <th class="span2">操作</th>
    </tr>
    <% datas.forEach(function(data,index){ %>
    <tr>
        <td>
            <%- data.name %>
        </td>
        <td>
            <% if(data.province.name!=data.city.name){%>
                <%- data.province.name %>
            <% } %>
            <%- data.city.name%>-<%- data.area.name%>-<%- data.addr %>
        </td>
        <td>
            <a id="t<%- data._id %>">详情/编辑</a>
            <div id="win<%- data._id %>" iconCls="icon-save" >
                <div style="position: relative">
                    <div style="width: 230px;height:300px;float: left;border: 1px dotted #9f9d93;position: absolute;top:50px;left: 700px">
                        <img id="img_poster<%-  data.id %>"  src="<%- data.intro %>" style="width: 230px;height: 300px">
                        <div class="circular" style="position: absolute;top:120px;left:50px;z-index:10;text-align:center;line-height: 20px;width:130px;height: 40px;background-color: #d77a03;">
                            <h4 style="color: white;line-height: 20px">详情</b></h4>
                        </div>
                        <div class="file-box" style="margin-top: 20px">
                            <form id="uploadPoster" method="post" enctype="multipart/form-data">
                                <input type='text' name='textfield' id='textfield<%- data._id%>' class='txt' style="margin-bottom: 0px"/>
                                <input type='button' class='btn' value='浏览...' />
                                <input type="file" name="file" class="file" id="fileToUpload<%- data._id%>" size="28" onchange="document.getElementById('textfield<%- data._id%>').value=this.value" />
                                <input type="submit" name="submit" class="btn" value="上传" onclick="return ajaxFileUpload('<%- data._id%>');"/>
                            </form>
                        </div>
                    </div>
                    <form class="form-horizontal" action="/manager/coffeeEdit" method="post">
                        <input type="hidden"  name="id" value="<%- data._id %>">
                        <fieldset>
                            <legend>咖啡厅编辑</legend>
                            <div class="control-group">
                                <label class="control-label">名称</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge"  name="name" value="<%- data.name %>">
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">地址</label>
                                <div class="controls">
                                    <select id="province<%- data._id %>" name="province" style="width: 100px" onchange="loadCity(this,'<%- data._id %>');">
                                        <option value="">请选择</option>
                                        <% provinceDatas.forEach(function(provinceData,index){%>
                                        <option value="<%- provinceData._id %>"><%- provinceData.name %></option>
                                        <% }) %>
                                    </select>
                                    <select id="city<%- data._id %>" name="city" style="width: 100px" onchange="loadArea(this,'<%- data._id %>')">
                                        <option value="">请选择</option>
                                    </select>
                                    <select id="area<%- data._id %>" name="area" style="width: 100px">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="username">详细地址</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge"  name="addr" value="<%- data.addr %>">
                                </div>
                            </div>
                            <!--<div class="control-group">-->
                            <!--<label class="control-label" for="password">简介</label>-->
                            <!--<div class="controls">-->

                            <!--<script id="container" name="intro" type="text/plain"></script>-->
                            <!--</div>-->
                            <!--</div>-->
                            <div style="height: 200px"></div>
                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary">编辑提交</button>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </td>
        <td>
            <a class="btn btn-danger btn-small" onclick="goDelete('<%- data._id %>')">删除</a>

        </td>
    </tr>
    <script>
        $('#win<%- data._id %>').window({
            title: '菜单',
            width: 1111,
            modal: true,
            shadow: true,
            closed: true,
            height: 550,
            maximizable : false,
            resizable:false

        });
        $("#t<%- data._id %>").click(function(){

            $('#win<%- data._id %>').window('open');
        })

    </script>
    <% }) %>
</table>

<hr>


<div class="span12">
    <div id="page1"></div>
</div>
<!-- 主题内容end -->
<%- include footer %>
<script>
    function goDelete(id){
        var prompt=confirm("你确定删除该记录吗？？");

        if(prompt){

            window.location.href="/manager/delCoffee?id="+id;
        }
    }
    function test(){
//        alert($(window).height())       //可见区域高度
//        alert($(window).width())        //可见区域宽度
//        alert($(document).height())     //整个页面高度
//        alert($(document).width())      //整个页面宽度
        alert($(document).scrollTop())  //获取滚动条到顶部的垂直高度
    }
    $(function(){
        //获得浏览器参数

        $.extend({
            getUrlVars: function(){
                var vars = [];
                var hash;
                var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                console.log(hashes);
                for(var i = 0; i < hashes.length; i++){
                    hash = hashes[i].split('=');
                    vars.push(hash[0]);
                    vars[hash[0]] = hash[1];
                }
                return vars;
            },
            getUrlVar: function(name){
                return $.getUrlVars()[name];
            }
        });

        //封装浏览器参数
        var composeUrlParams=function(){
            var param='';
            $.each($.getUrlVars(), function(i, item) {
                if(item!='num'){
                    var val=$.getUrlVar(item);
                    if(val) param += "&" + item+"="+val;
                }
            });
            return param;
        }
        var options = {
            currentPage:<%- page.num %>,                //当前页，css样式同其他页不同
            totalPages:<%- page.pageCount %>,           //总页数
            numberOfPages:5,                            //导航最多显示页数
            pageUrl: function(type, page, current) {    //页面跳转
                if(page!=<%- page.num %>){
                    return "/manager/coffee?num="+ page+composeUrlParams();
                }
            }
        }
        $('#page1').bootstrapPaginator(options);
    })
</script>
<script>
    function loadCity(obj,id){
        $.ajax({
            type: "get",
            url: "/manager/loadCity?pid="+obj.value,
            success: function(result){
                $("#city"+id).html(result);
            }
        });
    }
    function loadArea(obj,id){
        $.ajax({
            type: "get",
            url: "/manager/loadArea?cid="+obj.value,
            success: function(result){
                $("#area"+id).html(result);
            }
        });
    }
    function ajaxFileUpload(id) {

        $.ajaxFileUpload({
            url : '/manager/uploadPoster',// servlet请求路径
            secureuri : false,
            fileElementId : 'fileToUpload'+id,// 上传控件的id
            dataType:'text',
            success : function(data) {
                //alert(data);
                //alert(data.replace(/<.*?>/ig,''));

                if(data.indexOf('url')<0){
                    alert(data.replace(/<.*?>/ig,''));
                }
                eval("var jsobjjson="+data.replace(/<.*?>/ig,''));
                //alert(decodeURIComponent(jsobjjson.url))

                if(jsobjjson.state=='上传成功'){
                    //alert('111')
                    $("#img_poster"+id).attr("src",decodeURIComponent(jsobjjson.url));
                }
            },
            error : function(data, status, e) {
                alert('上传出错');
            }
        })

        return false;

    }
</script>
